//
//  HomeTableView.m
//  MiWei
//
//  Created by 刘星 on 2017/10/13.
//  Copyright © 2017年 miwei. All rights reserved.
//

#import "HomeTableView.h"
#import "Base.h"
#import "ServiceTableSectionHeadView.h"
#import "HomeTableViewCourseCell.h"

@interface HomeTableView () <UITableViewDataSource, UITableViewDelegate>

@end

@implementation HomeTableView

static NSString *activityCellindentifier = @"HomeTableViewCourseCell";

- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style {
    self = [super initWithFrame:frame style:style];
    if (self) {
        [self configView];
    }
    return self;
}

- (void)configView {
    [self registerNib:[UINib nibWithNibName:@"HomeTableViewCourseCell" bundle:nil] forCellReuseIdentifier:activityCellindentifier];
    self.dataSource = self;
    self.delegate = self;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return (kScreenWidth* 430)/ 750 + 8;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 67;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    ServiceTableSectionHeadView *sectionHeadView = [[ServiceTableSectionHeadView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 67)];
    sectionHeadView.title = @"热门推荐";
    return sectionHeadView;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.hotRecomendListArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HomeTableViewCourseCell *cell = [tableView dequeueReusableCellWithIdentifier:activityCellindentifier];
    HomeListModel *model = self.hotRecomendListArray[indexPath.row];
    cell.listModel = model;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // 去掉点击效果
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    HomeTableViewCourseCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.selected = NO;
//    HomeListModel *model = self.dataArray[indexPath.row];
//    // 点击跳转话题
//    [self.homeViewModel.hotRecommendItemCommand execute:model];
}

- (NSMutableArray *)hotRecomendListArray {
    if (_hotRecomendListArray == nil) {
        _hotRecomendListArray = [NSMutableArray array];
    }
    return _hotRecomendListArray;
}

@end
